EDA for Interest Rate
Interest rate is a critical macroeconomic variable that plays a key role in shaping economic growth and financial stability. Exploratory Data Analysis (EDA) is a powerful technique for analyzing interest rate data and gaining insights into the factors driving interest rate movements. In this page, we will explore various EDA techniques that can be applied to interest rate data, such as time series analysis, autocorrelation analysis, seasonality analysis, moving averages, and detrending. By the end of this page, you will have a better understanding of how to apply EDA techniques to interest rate data and draw valuable insights from it.
Time Series Plot
Code
#import the data
interest_data <- read.csv("DATA/RAW DATA/interest-rate.csv")
#change date format
interest_data$Date <- as.Date(interest_data$Date , "%m/%d/%Y")
#export the cleaned data
interest_clean_data <- interest_data
write.csv(interest_clean_data, "DATA/CLEANED DATA/interest_rate_clean_data.csv", row.names=FALSE)
#plot interest rate
fig <- plot_ly(interest_data, x = ~Date, y = ~value, type = 'scatter', mode = 'lines',line = list(color='rgb(176,224,230)'))
fig <- fig %>% layout(title = "U.S Interest Rate: January 2010 - March 2023",xaxis = list(title = "Time"),yaxis = list(title ="Interest Rate"))
figThe interest rate in the United States has exhibited fluctuations from 2010 to 2022. In the years following the 2008 global financial crisis, the interest rate was very low. The interest rate in the US was very low and stable from 2010 to 2018. During this period, the Federal Reserve implemented several monetary policy measures, such as quantitative easing and forward guidance, in order to stimulate the economy and support economic recovery after the global financial crisis.
Starting in 2018, the Federal Reserve began a gradual process of raising interest rates as the US economy continued to improve. This process of increasing interest rates was driven by a combination of factors such as low unemployment rates, a steady increase in GDP, and the need to prevent inflation from rising too quickly.
However, as global economic conditions became more uncertain, the Federal Reserve began to pause its process of increasing interest rates. The US-China trade war and concerns about the potential impact of Brexit led to a more cautious approach from the Federal Reserve. In 2019, the Federal Reserve lowered interest rates three times in response to these external factors.
In 2020, the COVID-19 pandemic caused a major shock to the global economy, leading the Federal Reserve to take unprecedented measures to support the US economy. The Federal Reserve lowered interest rates to near-zero levels, implemented quantitative easing, and established several lending facilities to support businesses and households.
There is no clear evidence of a relationship between the variability of the series and its level, which suggests that an additive model might be more appropriate. Additionally, an additive model can be useful when the trend is relatively stable and the amplitude of seasonal fluctuations remains constant over time.
Decomposed Time Series
Code
#convert to ts data
myts<-ts(interest_data$value,frequency=12,start=c(2010/1/1))
#decomposition
orginial_plot <- autoplot(myts,xlab ="Year", ylab = "Interest Rate", main = "U.S Interest Rate: January 2010 - March 2023")
decompose = decompose(myts,"additive")
autoplot(decompose)Code
trendadj <- myts/decompose$trend
decompose_adjtrend_plot <- autoplot(trendadj,ylab='seasonal') +ggtitle('Adjusted trend component in the additive time series model')
seasonaladj <- myts/decompose$seasonal
decompose_adjseasonal_plot <- autoplot(seasonaladj,ylab='seasonal') +ggtitle('Adjusted seasonal component in the additive time series model')
grid.arrange(orginial_plot, decompose_adjtrend_plot,decompose_adjseasonal_plot, nrow=3)When compared to the original figure, the corrected seasonal component shows seasonality in the model, but the adjusted trend component has a stable trend through time.
Lag Plots
Code
#Lag plots
gglagplot(myts, do.lines=FALSE, lags=1)+xlab("Lag 1")+ylab("Yi")+ggtitle("Lag Plot for U.S Interest Rate: January 2010 - March 2023")Code
#monthly data
mean_data <- interest_data %>%
mutate(month = month(Date), year = year(Date)) %>%
group_by(year, month) %>%
summarize(mean_value = mean(value))
month<-ts(mean_data$mean_value,star=decimal_date(as.Date("2010-01-01",format = "%Y-%m-%d")),frequency = 12)
#Lag plot for monthly data
ts_lags(month)There should be a strong relationship between the series and the pertinent lag from January 2010 to March 2023 because there is a positive correlation and an inclination angle of 45 degrees in the lag plot. This is the characteristic lag plot of a process with strong positive autocorrelation. One observation and the next have a significant link, making such processes remarkably non-random. Investigating seasonality also involves graphing observations over a larger range of time intervals, or the lags. To make the time series data easier to understand and create graphs with more clarity, the time series data is combined with monthly data using the mean function. A closer look at the previous graph indicates that there are more dots on the diagonal line at 45 degrees. The second graph displays the variable’s monthly variation along the vertical axis. The lines link the points in the order of time. There is a correlation and it is significantly positive, supporting the strong seasonality of the data.
Seasonality
Code
# Create seasonal plot
ts_heatmap(month,color = "Greens", title = 'Seasonality U.S Interest Rate: 2010 - 2021')Code
# Create a line graph for each year with months on the x-axis
ggseasonplot(month, datecol = "date", valuecol = "value")+ggtitle("Seasonal Yearly Plot forU.S Interest Rate: 2010 - 2021")The seasonality plots shows that series follow seasonality, as the heat map shows no much difference with each year and the line graph shows some kind of seasonality as th is rise in the rate during september this can be confirmed using the acf plot.
Moving Average
Code
#SMA Smoothing
ma <- autoplot(month, series="interest_data") +
autolayer(ma(month,5), series="4 Month MA") +
xlab("Year") + ylab("GWh") +
ggtitle("Interest Rate January 2010 - March 2023 (4 Month Moving Average)") +
scale_colour_manual(values=c("Data"="grey50","4 Month MA"="red"),
breaks=c("Data","4 Month MA"))
maCode
#SMA Smoothing
ma <- autoplot(month, series="interest_data") +
autolayer(ma(month,13), series="1 Year MA") +
xlab("Year") + ylab("GWh") +
ggtitle("Interest Rate January 2010 - March 2023 (1 Year Moving Average)") +
scale_colour_manual(values=c("Data"="grey50","1 Year MA"="red"),
breaks=c("Data","1 Year MA"))
maCode
#SMA Smoothing
ma <- autoplot(month, series="interest_data") +
autolayer(ma(month,37), series="3 Year MA") +
xlab("Year") + ylab("GWh") +
ggtitle("Interest Rate January 2010 - March 2023 (3 Year Moving Average)") +
scale_colour_manual(values=c("Data"="grey50","3 Year MA"="red"),
breaks=c("Data","3 Year MA"))
maCode
#SMA Smoothing
ma <- autoplot(month, series="interest_data") +
autolayer(ma(month,61), series="5 Year MA") +
xlab("Year") + ylab("GWh") +
ggtitle("Interest Rate January 2010 - March 2023 (5 Year Moving Average)") +
scale_colour_manual(values=c("Data"="grey50","5 Year MA"="red"),
breaks=c("Data","5 Year MA"))
maThe Interest Rate is displayed for the time period between January 2010 and March 2023 in the four plots above, which have been smoothed using 4-month, 1-year, 3-year, and 5-year moving averages. We can observe from the graphs that the moving average values have been rising over time. Given that it captures the short-term differences in stock prices, the 4-month MA plot exhibits a great deal of volatility, which is to be expected. The 1-year, 3-year, and 5-year MA plots, on the other hand, tame the oscillations and reveal the general direction of stock prices. We can see that the 5-year MA plot, which considers a longer time period than the other plots, shows a trend that is smoother. The 3-year MA plot similarly shows a fairly smooth trend, but unlike the 5-year MA plot, it also shows shorter-term variability. Even more susceptible to short-term changes in stock prices is the 1-year MA plot. The trend for Interest Rate isn’t stable, there is fluctuation in the trend but it seems that there is upward trend from 2020.
Autocorrelation Time Series
Code
#ACF plots for monthly data
ggAcf(myts)+ggtitle("ACF Plot for Interest Rate: January 2010 - March 2023")Code
#PACF plots for monthly data
ggPacf(myts)+ggtitle("PACF Plot for Interest Rate: January 2010 - March 2023")Code
# ADF Test
tseries::adf.test(myts)
Augmented Dickey-Fuller Test
data: myts
Dickey-Fuller = -1.3832, Lag order = 5, p-value = 0.8336
alternative hypothesis: stationary
The autocorrelation function plot, which is the acf graph for monthly data, clearly shows autocorrelation in lag and seasonality. The series appears to be seasonal, according to the lag plots and autocorrelation plots displayed above, proving that it is not stable. The Augmented Dickey-Fuller Test, which reveals that the series is not stationary if the p value is more than 0.05, was also used to validate it.
Detrend and Differenced Time Series
Code
fit = lm(myts~time(myts), na.action=NULL)
summary(fit)
Call:
lm(formula = myts ~ time(myts), na.action = NULL)
Residuals:
Min 1Q Median 3Q Max
-0.97697 -0.33564 0.00804 0.23469 1.46755
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -18.300672 20.233604 -0.904 0.367
time(myts) 0.009339 0.010034 0.931 0.353
Residual standard error: 0.4839 on 157 degrees of freedom
Multiple R-squared: 0.005488, Adjusted R-squared: -0.0008465
F-statistic: 0.8664 on 1 and 157 DF, p-value: 0.3534
Code
plot1 <- ggAcf(myts, 48, main="Original Data: Interest Rate")
plot2 <- ggAcf(resid(fit), 48, main="Detrended data")
plot3 <- ggAcf(diff(myts), 48, main="First differenced data")
grid.arrange(plot1, plot2, plot3,nrow=3)The estimated slope coefficient β1, 0.00933. With a standard error of 0.010034, yielding a significant estimated increase of stock price is very less yearly. Equation of the fit for stationary process: \[\hat{y}_{t} = x_{t}+(18.300672)-(0.00933.)t\]
From the above graph we can say that there is high correlation in the original plot, but in the detrended plot the correlation is reduced but there is still high correlation in the detrended data.But when the first order difference is applied the high correlation is removed but there is seasonal correlation.
As depicted in the above figure, the series is now stationary and ready for future study.